Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import { NextResponse } from "next/server";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
import { getPairing, pairingStatus } from "@/lib/app-pairing";
import { sessionUsername } from "@/lib/patient/session-username";
export const dynamic = "force-dynamic";
/**
* GET /api/patient/app-pairing/{pairingId}
*
* Polled by the patient screen while the QR code is showing: `pending` until
* the phone registers, then `connected` with its name, or `expired` when the
* two minutes ran out. A pairing is visible only to the login that started it;
* anyone else gets the same 404 as for one that never existed.
*/
export async function GET(
_request: Request,
{ params }: { params: Promise<{ pairingId: string }> },
) {
const auth = await requireAuth(["PATIENT"]);
if (isAuthError(auth)) return auth;
const username = await sessionUsername();
const { pairingId } = await params;
let pairing;
try {
pairing = username ? await getPairing(pairingId, username) : null;
} catch (err) {
console.error("GET /api/patient/app-pairing/[pairingId]:", err);
return NextResponse.json({ error: "Neo4j unavailable" }, { status: 502 });
}
if (!pairing) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
return NextResponse.json({
pairingId: pairing.id,
status: pairingStatus(pairing),
expiresAt: new Date(pairing.expiresAt).toISOString(),
...(pairing.deviceName ? { deviceName: pairing.deviceName } : {}),
});
}
|